<?php


class Controller extends CController{
	public $code_url;
	public $breadcrumbs;
	public $menu;
	
	public function init(){
	/*
	
		$o = new SaeTOAuthV2( WB_AKEY , WB_SKEY );


		if(!empty($_SESSION['token']['access_token'])){
			$code_url = Yii::app()->createUrl('/site/index');
		}else{
			$code_url = $o->getAuthorizeURL( WB_CALLBACK_URL );
		}
		//echo $code_url;
		
		$this->code_url=$code_url;

		if(!empty($_SESSION['token']['access_token'])){
			$c = new SaeTClientV2( WB_AKEY , WB_SKEY , $_SESSION['token']['access_token'] );
			//$c = new SaeTClientV2( WB_AKEY , WB_SKEY , $_REQUEST['viewer'] );
			$ms  = $c->home_timeline(); // done
			$uid_get = $c->get_uid();
			$uid = $uid_get['uid'];
			$user_message = $c->show_user_by_id( $uid);
			//var_dump($_SESSION);
			//var_dump($_REQUEST);
			//var_dump($ms);
		}

		
		
		$this->code_url=$code_url;
	*/
	
	}
	
	
	
	public function filterToken($filterChain)
	{
		$o = new weibo( WB_AKEY , WB_SKEY );


		if(!empty($_SESSION['token']['access_token'])){
			$code_url = Yii::app()->createUrl('/site/index');
		}else{
			$code_url = $o->getAuthorizeURL( WB_CALLBACK_URL );
		}
		//echo $code_url;
		
		$this->code_url=$code_url;

		if(!empty($_SESSION['token']['access_token'])){
			$c = new SaeTClientV2( WB_AKEY , WB_SKEY , $_SESSION['token']['access_token'] );
			//$c = new SaeTClientV2( WB_AKEY , WB_SKEY , $_REQUEST['viewer'] );
			$ms  = $c->home_timeline(); // done
			$uid_get = $c->get_uid();
			$uid = $uid_get['uid'];
			$user_message = $c->show_user_by_id( $uid);
			//var_dump($_SESSION);
			//var_dump($_REQUEST);
			//var_dump($ms);
		}

		
		
		$this->code_url=$code_url;
		$this->redirect($code_url);
	}
	
	public function filters()
    {
        return array(
            'Token - index',

        );
    }



}


?>